import vtk
import connect2
import myImageViewer
reload(myImageViewer)

filename='C:/Lib/JointTrack/branches/bryan/Images/ushortim080-LAT.tif'
ext=filename[filename.find('.'):]
vtk2itk = connect2.vtk2itk()
viewer = myImageViewer.Viewer()

if (ext == '.tif') or (ext == '.tiff'):
    reader=vtk.vtkTIFFReader()
elif (ext == '.png'):
    reader=vtk.vtkPNGReader()
elif (ext == '.jpg') or (ext == '.jpeg'):
    reader=vtk.vtkJPEGReader()
elif (ext == '.bmp'):
    reader=vtk.vtkBMPReader()
else:
    print "Image File format ", ext, " is not currently supported"
    out= -1

reader.SetFileName(filename)
reader.Update()
vtk2itk.SetInput(reader.GetOutput())
out = vtk2itk.GetOutput()
viewer.ViewNoFlip(out)

writer=vtk.vtkPNGWriter()
writer.SetInput(reader.GetOutput())
writer.SetFileName(filename[0:-4]+'_out.png')
writer.Write()


